package com.music.music.controller;

import com.music.common.core.utils.poi.ExcelUtil;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.web.page.TableDataInfo;
import com.music.common.log.annotation.Log;
import com.music.common.log.enums.BusinessType;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.music.domain.Collect;
import com.music.music.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户收藏Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/collect")
public class CollectController extends BaseController
{
    @Resource
    private CollectService collectService;

    /**
     * 查询用户收藏列表
     */
    @RequiresPermissions("music:collect:list")
    @GetMapping("/list")
    public TableDataInfo list(Collect collect)
    {
        startPage();
        List<Collect> list = collectService.selectCollectList(collect);
        return getDataTable(list);
    }

    /**
     * 导出用户收藏列表
     */
    @RequiresPermissions("music:collect:export")
    @Log(title = "用户收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Collect collect)
    {
        List<Collect> list = collectService.selectCollectList(collect);
        ExcelUtil<Collect> util = new ExcelUtil<Collect>(Collect.class);
        util.exportExcel(response, list, "用户收藏数据");
    }

    /**
     * 获取用户收藏详细信息
     */
    @RequiresPermissions("music:collect:query")
    @GetMapping(value = "/{collectUserId}")
    public AjaxResult getInfo(@PathVariable("collectUserId") Long collectUserId)
    {
        return success(collectService.selectCollectByCollectUserId(collectUserId));
    }

    /**
     * 新增用户收藏
     */
    @RequiresPermissions("music:collect:add")
    @Log(title = "用户收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Collect collect)
    {
        return toAjax(collectService.insertCollect(collect));
    }

    /**
     * 修改用户收藏
     */
    @RequiresPermissions("music:collect:edit")
    @Log(title = "用户收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Collect collect)
    {
        return toAjax(collectService.updateCollect(collect));
    }

    /**
     * 删除用户收藏
     */
    @RequiresPermissions("music:collect:remove")
    @Log(title = "用户收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectUserIds}")
    public AjaxResult remove(@PathVariable Long[] collectUserIds)
    {
        return toAjax(collectService.deleteCollectByCollectUserIds(collectUserIds));
    }
}
